<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>字母异位词分组</title>
</head>
<body>
  <script>
    function fn(strs) {
      const map = new Map();
      for (let str of strs) {
          let array = Array.from(str);//字符转成数组
          array.sort();//排序
          let key = array.toString();
          let list = map.get(key) ? map.get(key) : new Array();//从map中取到相应的数组
          list.push(str);//加入数组
          map.set(key, list);//重新设置该字符的数组
      }
      return Array.from(map.values());//map中的value转成数组
    }
    console.log(fn(["eat","tea","tan","ate","nat","bat"]))
  </script>
</body>
</html>